package org.clockworkmages.games.anno1186.scripting;

import java.util.HashMap;
import java.util.Map;

import org.clockworkmages.games.anno1186.GameState;
import org.clockworkmages.games.anno1186.GameStateService;
import org.clockworkmages.games.anno1186.Injected;
import org.clockworkmages.games.anno1186.model.situation.Situation;

public class SituationScriptingWrapper {

	@Injected
	private GameStateService gameStateService;

	public void addState(String stateId) {
		GameState gameState = gameStateService.getGameState();
		Situation situation = gameState.getCurrentSituation();
		String situationId = situation.getId();
		Map<String, String> state = gameState.getSituationState().get(
				situationId);
		if (state == null) {
			state = new HashMap<String, String>();
			gameState.getSituationState().put(situationId, state);
		}
		state.put(stateId, "");
	}

	public void setState(String stateId, String value) {
		GameState gameState = gameStateService.getGameState();
		Situation situation = gameState.getCurrentSituation();
		String situationId = situation.getId();
		Map<String, String> state = gameState.getSituationState().get(
				situationId);
		if (state == null) {
			state = new HashMap<String, String>();
			gameState.getSituationState().put(situationId, state);
		}
		state.put(stateId, value);
	}

	public boolean hasState(String stateId) {
		GameState gameState = gameStateService.getGameState();
		Situation situation = gameState.getCurrentSituation();
		String situationId = situation.getId();
		Map<String, String> state = gameState.getSituationState().get(
				situationId);
		if (state == null) {
			return false;
		}
		return state.containsKey(stateId);
	}

	public String getState(String stateId) {
		GameState gameState = gameStateService.getGameState();
		Situation situation = gameState.getCurrentSituation();
		String situationId = situation.getId();
		Map<String, String> state = gameState.getSituationState().get(
				situationId);
		if (state == null) {
			return null;
		}
		return state.get(stateId);
	}

}
